# Maintainer: Rémi BERTHO <remi.bertho@dalan.fr>

_realname=podofo
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.9.6
pkgrel=2
pkgdesc="A C++ library to work with the PDF file format (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://podofo.sourceforge.io/"
license=('GPL')
depends=("${MINGW_PACKAGE_PREFIX}-fontconfig"
         "${MINGW_PACKAGE_PREFIX}-libtiff"
         "${MINGW_PACKAGE_PREFIX}-libidn"
         "${MINGW_PACKAGE_PREFIX}-libjpeg-turbo"
         "${MINGW_PACKAGE_PREFIX}-lua"
         "${MINGW_PACKAGE_PREFIX}-openssl")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-cppunit")
source=("https://downloads.sourceforge.net/${_realname}/${_realname}-${pkgver}.tar.gz"
        "find-modules.patch"
        "fix-export.patch"
        "remove-broken-command.patch")
sha256sums=('e9163650955ab8e4b9532e7aa43b841bac45701f7b0f9b793a98c8ca3ef14072'
            '9e04e9a009520f12876d9c67b2af44bab5266782a59d53057a59d26f0e8a4294'
            'f4946fc54d6a746bf563aaef968db4efc09015de5d98a538c1c1cf5e529656c4'
            '3e5e7188c15a75652d2ab01667ef15ef3799e79d0875df9a6d98224398bb3cdc')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i "${srcdir}/find-modules.patch"
  patch -p1 -i "${srcdir}/fix-export.patch"
  patch -p1 -i "${srcdir}/remove-broken-command.patch"
}

build() {
  rm -rf build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST}
  cd build-${MINGW_CHOST}
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -Wno-dev \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DFREETYPE_INCLUDE_DIR=${MINGW_PREFIX}/include/freetype2 \
    -DCMAKE_BUILD_TYPE=Release \
    -DPODOFO_BUILD_SHARED=1 \
    -DPODOFO_HAVE_JPEG_LIB=1 \
    -DPODOFO_HAVE_PNG_LIB=1 \
    -DPODOFO_HAVE_TIFF_LIB=1 \
    ../${_realname}-${pkgver}

  make
}

package() {
  cd build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install
}
